﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MyLib.MyBase.MyWeb;
using MyChocCuoi.Setting;
using MyLib.MyUtility;
namespace MyLoad.LoadStatic
{
    public class LBanner : MyLoadWeb
    {
        public LBanner(MyASHX CurrentPage)
        {
            this.CurrentPage = CurrentPage;
            TemplatePath = "~/Templates/Static/Banner.html";
            Init();
        }
        // Hàm trả về chuỗi có chứa mã HTML
        protected override string BuildHTML()
        {
            try
            {
                string CssHome = string.Empty, CssNew = string.Empty, CssImage = string.Empty, CssVideo = string.Empty;
                if (CurrentPage.PageCode.Equals(WebSetting.ListPage.Home.ToString(), StringComparison.InvariantCultureIgnoreCase))
                {
                    CssHome = "selected";
                }
                else if (CurrentPage.PageCode.Equals(WebSetting.ListPage.Image.ToString(), StringComparison.InvariantCultureIgnoreCase))
                {
                    CssImage = "selected";
                }
                else if (CurrentPage.PageCode.Equals(WebSetting.ListPage.New.ToString(), StringComparison.InvariantCultureIgnoreCase))
                {
                    CssNew = "selected";
                }
                else if (CurrentPage.PageCode.Equals(WebSetting.ListPage.Video.ToString(), StringComparison.InvariantCultureIgnoreCase))
                {
                    CssVideo = "selected";
                }

                //Kiểm tra và đăng nhập từ cookie
                WebSetting.CheckCookieLogin();

                string HTMLLogin = "<a href=\"" + MyConfig.Domain + "/Dang-nhap.html\" class=\"link inline\">Đăng nhập</a>";

                if (!WebSetting.MemberLogined.IsNull)
                {
                    //Load html đã đăng nhập
                    string format = "<a class=\"avatar link drop-arrow\" href=\"javascript:void(0);\"><img src=\"{0}\" /><span class=\"name inline\">Tôi<span class=\"arrow\"></span></span>";
                    HTMLLogin = string.Format(format, new string[] { WebSetting.MemberLogined.GetImage() });
                }

                return LoadTemplateByArray(TemplatePath, new string[] { CssNew,CssHome,  CssImage, CssVideo,
                                                                        HTMLLogin,WebSetting.MemberLogined.MemberID.ToString()});
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
